package com.tanhua.manage.controller;


import com.tanhua.manage.pojo.Admin;
import com.tanhua.manage.pojo.AdminRole;
import com.tanhua.manage.service.PressionService;
import com.tanhua.manage.vo.AdminRoleVo;
import com.tanhua.manage.vo.Pager;
import com.tanhua.manage.vo.RoleVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/management/pression")
public class PressionController {
    @Autowired
    private PressionService pressionService;

    //1.角色管理列表查询
    @GetMapping("/findRoles")
    public Pager<RoleVo> findRoleByPage(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                       @RequestParam(name = "pagesize", defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "roleName",required = false) String roleName){
        return this.pressionService.findRoleByPage(page,pageSize,roleName);
    }

    //1.1新增角色
    @PostMapping("/op1")
    public String insertRole(@RequestBody AdminRole adminRole,String pressionIds){
        return this.pressionService.insertRole(adminRole,pressionIds);
    }
    // 1.2 删除角色
    @DeleteMapping("op2")
    //@GetMapping("op2")
    public String deleteRoleById(Integer id){
        return this.pressionService.deleteRoleById(id);
    }
    // 1.3修改角色
    @PostMapping("op3")
    public String updateRoleById(@RequestBody AdminRole adminRole){
        return this.pressionService.updateRoleById(adminRole);
    }
    // 1.4 修改状态
    @PostMapping("op4")
    public String updateRoleState(Integer id,Integer state){
        return this.pressionService.updateRoleState(id,state);
    }

    //2. 账号权限管理列表分页查询
    @GetMapping("/findAdminPression")
    public Pager<AdminRoleVo> findAdminPression(
            @RequestParam(name = "page", defaultValue = "1") Integer page,
            @RequestParam(name = "pagesize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "adminName",required = false) String adminName){
        return this.pressionService.findAdminPression(page,pageSize,adminName);
    }
    // 2.1 新增管理员用户
    @PostMapping("op5")
    public String insertAdmin(@RequestBody Admin admin,String roleIds){
        return this.pressionService.insertAdmin(admin,roleIds);
    }
    // 2.2修改管理员用户
    @PostMapping("op6")
    public String updateAdminById(@RequestBody Admin admin){
        return this.pressionService.updateAdminById(admin);
    }
    // 2.3 删除管理员用户
    @GetMapping("op7")
    public String deleteAdminById(Integer id){
        return this.pressionService.deleteAdminById(id);
    }
    //2.4 修改密码
    @PostMapping("op8")
    public String updateAdminPasswordById(@RequestParam("id") Integer id,
                                          @RequestParam("oldPassword") String oldPassword,
                                          @RequestParam("newPassword") String newPassword,
                                          @RequestParam("newPasswordAgain") String newPasswordAgain){
        return this.pressionService.updateAdminPasswordById(id,oldPassword,newPassword,newPasswordAgain);
    }
}